<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  
  <title>CentOS上安装mysql | 欢迎来到guo的博客!</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta name="description" content="安装mysql去官网上查看  https:&#x2F;&#x2F;dev.mysql.com&#x2F;downloads&#x2F;repo&#x2F;yum&#x2F;       mysql的yum仓库 这里安装mysql的源 1yum install -y https:&#x2F;&#x2F;repo.mysql.com&#x2F;&#x2F;mysql80-community-release-el7-3.noarch.rpm 检查MySQL源是否">
<meta property="og:type" content="article">
<meta property="og:title" content="CentOS上安装mysql">
<meta property="og:url" content="http://shangguan-lingfeng.gitee.io/blog1/2021/04/21/CentOS%E4%B8%8A%E5%AE%89%E8%A3%85mysql/index.html">
<meta property="og:site_name" content="欢迎来到guo的博客!">
<meta property="og:description" content="安装mysql去官网上查看  https:&#x2F;&#x2F;dev.mysql.com&#x2F;downloads&#x2F;repo&#x2F;yum&#x2F;       mysql的yum仓库 这里安装mysql的源 1yum install -y https:&#x2F;&#x2F;repo.mysql.com&#x2F;&#x2F;mysql80-community-release-el7-3.noarch.rpm 检查MySQL源是否">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2021-04-20T16:00:00.000Z">
<meta property="article:modified_time" content="2021-04-21T14:04:21.511Z">
<meta property="article:author" content="Jerry">
<meta property="article:tag" content="CentOS">
<meta name="twitter:card" content="summary">
  
    <link rel="alternate" href="/blog1/atom.xml" title="欢迎来到guo的博客!" type="application/atom+xml">
  
  
    <link rel="shortcut icon" href="/blog1/favicon.png">
  
  
    
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/typeface-source-code-pro@0.0.71/index.min.css">

  
  
<link rel="stylesheet" href="/blog1/css/style.css">

  
    
<link rel="stylesheet" href="/blog1/fancybox/jquery.fancybox.min.css">

  
<meta name="generator" content="Hexo 5.3.0"></head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/blog1/" id="logo">欢迎来到guo的博客!</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/blog1/">Home</a>
        
          <a class="main-nav-link" href="/blog1/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/blog1/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="Suche"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Suche"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="http://shangguan-lingfeng.gitee.io/blog1"></form>
      </div>
    </div>
  </div>
</header>

      <div class="outer">
        <section id="main"><article id="post-CentOS上安装mysql" class="h-entry article article-type-post" itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
  <div class="article-meta">
    <a href="/blog1/2021/04/21/CentOS%E4%B8%8A%E5%AE%89%E8%A3%85mysql/" class="article-date">
  <time class="dt-published" datetime="2021-04-20T16:00:00.000Z" itemprop="datePublished">2021-04-21</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="p-name article-title" itemprop="headline name">
      CentOS上安装mysql
    </h1>
  

      </header>
    
    <div class="e-content article-entry" itemprop="articleBody">
      
        <h2 id="安装mysql"><a href="#安装mysql" class="headerlink" title="安装mysql"></a>安装mysql</h2><p>去官网上查看  <a target="_blank" rel="noopener" href="https://dev.mysql.com/downloads/repo/yum/">https://dev.mysql.com/downloads/repo/yum/</a>       mysql的yum仓库</p>
<p>这里安装mysql的源</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum install -y https:&#x2F;&#x2F;repo.mysql.com&#x2F;&#x2F;mysql80-community-release-el7-3.noarch.rpm</span><br></pre></td></tr></table></figure>
<p>检查MySQL源是否安装成功</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">yum repolist enabled</span><br><span class="line"></span><br><span class="line">查看结果：</span><br><span class="line">mysql-connectors-community                               | 2.6 kB     00:00     </span><br><span class="line">mysql-tools-community                                    | 2.6 kB     00:00     </span><br><span class="line">mysql80-community                                        | 2.6 kB     00:00     </span><br><span class="line">(1&#x2F;3): mysql-connectors-community&#x2F;x86_64&#x2F;primary_db        |  77 kB   00:01     </span><br><span class="line">(2&#x2F;3): mysql80-community&#x2F;x86_64&#x2F;primary_db                 | 153 kB   00:02     </span><br><span class="line">(3&#x2F;3): mysql-tools-community&#x2F;x86_64&#x2F;primary_db             |  87 kB   00:03     </span><br><span class="line">repo id                           repo name                               status</span><br><span class="line">base&#x2F;7&#x2F;x86_64                     CentOS-7                                10,072</span><br><span class="line">epel&#x2F;x86_64                       Extra Packages for Enterprise Linux 7 - 13,581</span><br><span class="line">extras&#x2F;7&#x2F;x86_64                   CentOS-7                                   468</span><br><span class="line">mysql-connectors-community&#x2F;x86_64 MySQL Connectors Community                 194</span><br><span class="line">mysql-tools-community&#x2F;x86_64      MySQL Tools Community                      126</span><br><span class="line">mysql80-community&#x2F;x86_64          MySQL 8.0 Community Server                 247</span><br><span class="line">updates&#x2F;7&#x2F;x86_64                  CentOS-7                                 1,932</span><br><span class="line">repolist: 26,620</span><br></pre></td></tr></table></figure>


<p>源安装好以后，安装mysql服务</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum install mysql-community-server</span><br></pre></td></tr></table></figure>
<p>服务开始安装中…，需要安装 Total download size: 553 M，安装期间有yes直接yes</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br></pre></td><td class="code"><pre><span class="line">Resolving Dependencies</span><br><span class="line">--&gt; Running transaction check</span><br><span class="line">---&gt; Package mysql-community-server.x86_64 0:8.0.24-1.el7 will be installed</span><br><span class="line">--&gt; Processing Dependency: mysql-community-common(x86-64) &#x3D; 8.0.24-1.el7 for package: mysql-community-server-8.0.24-1.el7.x86_64</span><br><span class="line">--&gt; Processing Dependency: mysql-community-client(x86-64) &gt;&#x3D; 8.0.11 for package: mysql-community-server-8.0.24-1.el7.x86_64</span><br><span class="line">--&gt; Running transaction check</span><br><span class="line">---&gt; Package mysql-community-client.x86_64 0:8.0.24-1.el7 will be installed</span><br><span class="line">--&gt; Processing Dependency: mysql-community-client-plugins &#x3D; 8.0.24-1.el7 for package: mysql-community-client-8.0.24-1.el7.x86_64</span><br><span class="line">--&gt; Processing Dependency: mysql-community-libs(x86-64) &gt;&#x3D; 8.0.11 for package: mysql-community-client-8.0.24-1.el7.x86_64</span><br><span class="line">---&gt; Package mysql-community-common.x86_64 0:8.0.24-1.el7 will be installed</span><br><span class="line">--&gt; Running transaction check</span><br><span class="line">---&gt; Package mariadb-libs.x86_64 1:5.5.52-1.el7 will be obsoleted</span><br><span class="line">--&gt; Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64</span><br><span class="line">--&gt; Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64</span><br><span class="line">---&gt; Package mysql-community-client-plugins.x86_64 0:8.0.24-1.el7 will be installed</span><br><span class="line">---&gt; Package mysql-community-libs.x86_64 0:8.0.24-1.el7 will be obsoleting</span><br><span class="line">--&gt; Running transaction check</span><br><span class="line">---&gt; Package mysql-community-libs-compat.x86_64 0:8.0.24-1.el7 will be obsoleting</span><br><span class="line">---&gt; Package postfix.x86_64 2:2.10.1-6.el7 will be updated</span><br><span class="line">---&gt; Package postfix.x86_64 2:2.10.1-9.el7 will be an update</span><br><span class="line">--&gt; Finished Dependency Resolution</span><br><span class="line"></span><br><span class="line">Dependencies Resolved</span><br><span class="line"></span><br><span class="line">&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;</span><br><span class="line"> Package                        Arch   Version          Repository         Size</span><br><span class="line">&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;</span><br><span class="line">Installing:</span><br><span class="line"> mysql-community-libs           x86_64 8.0.24-1.el7     mysql80-community 4.0 M</span><br><span class="line">     replacing  mariadb-libs.x86_64 1:5.5.52-1.el7</span><br><span class="line"> mysql-community-libs-compat    x86_64 8.0.24-1.el7     mysql80-community 1.2 M</span><br><span class="line">     replacing  mariadb-libs.x86_64 1:5.5.52-1.el7</span><br><span class="line"> mysql-community-server         x86_64 8.0.24-1.el7     mysql80-community 428 M</span><br><span class="line">Installing for dependencies:</span><br><span class="line"> mysql-community-client         x86_64 8.0.24-1.el7     mysql80-community  45 M</span><br><span class="line"> mysql-community-client-plugins x86_64 8.0.24-1.el7     mysql80-community 189 k</span><br><span class="line"> mysql-community-common         x86_64 8.0.24-1.el7     mysql80-community 614 k</span><br><span class="line">Updating for dependencies:</span><br><span class="line"> postfix                        x86_64 2:2.10.1-9.el7   base              2.4 M</span><br><span class="line"></span><br><span class="line">Transaction Summary</span><br><span class="line">&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;</span><br><span class="line">Install  3 Packages (+3 Dependent packages)</span><br><span class="line">Upgrade             ( 1 Dependent package)</span><br><span class="line"></span><br><span class="line">Total download size: 482 M</span><br><span class="line">Is this ok [y&#x2F;d&#x2F;N]: y</span><br><span class="line">Downloading packages:</span><br><span class="line">Delta RPMs disabled because &#x2F;usr&#x2F;bin&#x2F;applydeltarpm not installed.</span><br><span class="line">warning: &#x2F;var&#x2F;cache&#x2F;yum&#x2F;x86_64&#x2F;7&#x2F;mysql80-community&#x2F;packages&#x2F;mysql-community-client-plugins-8.0.24-1.el7.x86_64.rpm: Header V3 DSA&#x2F;SHA1 Signature, key ID 5072e1f5: NOKEY</span><br><span class="line">Public key for mysql-community-client-plugins-8.0.24-1.el7.x86_64.rpm is not installed</span><br><span class="line">(1&#x2F;7): mysql-community-client-plugins-8.0.24-1.el7.x86_64. | 189 kB   00:02     </span><br><span class="line">(2&#x2F;7): mysql-community-common-8.0.24-1.el7.x86_64.rpm      | 614 kB   00:02     </span><br><span class="line">(3&#x2F;7): mysql-community-libs-8.0.24-1.el7.x86_64.rpm        | 4.0 MB   00:08     </span><br><span class="line">(4&#x2F;7): mysql-community-libs-compat-8.0.24-1.el7.x86_64.rpm | 1.2 MB   00:03     </span><br><span class="line">(5&#x2F;7): postfix-2.10.1-9.el7.x86_64.rpm                     | 2.4 MB   00:00     </span><br><span class="line">(6&#x2F;7): mysql-community-client-8.0.24-1.el7.x86_64.rpm      |  45 MB   01:15     </span><br><span class="line">(7&#x2F;7): mysql-community-server-8.0.24-1.el7.x86_64.rpm      | 428 MB   11:18     </span><br><span class="line">--------------------------------------------------------------------------------</span><br><span class="line">Total                                              709 kB&#x2F;s | 482 MB  11:35     </span><br><span class="line">Retrieving key from file:&#x2F;&#x2F;&#x2F;etc&#x2F;pki&#x2F;rpm-gpg&#x2F;RPM-GPG-KEY-mysql</span><br><span class="line">Importing GPG key 0x5072E1F5:</span><br><span class="line"> Userid     : &quot;MySQL Release Engineering &lt;mysql-build@oss.oracle.com&gt;&quot;</span><br><span class="line"> Fingerprint: a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5</span><br><span class="line"> Package    : mysql80-community-release-el7-3.noarch (installed)</span><br><span class="line"> From       : &#x2F;etc&#x2F;pki&#x2F;rpm-gpg&#x2F;RPM-GPG-KEY-mysql</span><br><span class="line">Is this ok [y&#x2F;N]: y</span><br><span class="line">Running transaction check</span><br><span class="line">Running transaction test</span><br><span class="line">Transaction test succeeded</span><br><span class="line">Running transaction</span><br><span class="line">  Installing : mysql-community-client-plugins-8.0.24-1.el7.x86_64           1&#x2F;9 </span><br><span class="line">  Installing : mysql-community-common-8.0.24-1.el7.x86_64                   2&#x2F;9 </span><br><span class="line">  Installing : mysql-community-libs-8.0.24-1.el7.x86_64                     3&#x2F;9 </span><br><span class="line">  Installing : mysql-community-client-8.0.24-1.el7.x86_64                   4&#x2F;9 </span><br><span class="line">  Installing : mysql-community-libs-compat-8.0.24-1.el7.x86_64              5&#x2F;9 </span><br><span class="line">  Updating   : 2:postfix-2.10.1-9.el7.x86_64                                6&#x2F;9 </span><br><span class="line">  Installing : mysql-community-server-8.0.24-1.el7.x86_64                   7&#x2F;9 </span><br><span class="line">  Cleanup    : 2:postfix-2.10.1-6.el7.x86_64                                8&#x2F;9 </span><br><span class="line">  Erasing    : 1:mariadb-libs-5.5.52-1.el7.x86_64                           9&#x2F;9 </span><br><span class="line">  Verifying  : mysql-community-server-8.0.24-1.el7.x86_64                   1&#x2F;9 </span><br><span class="line">  Verifying  : mysql-community-client-8.0.24-1.el7.x86_64                   2&#x2F;9 </span><br><span class="line">  Verifying  : mysql-community-common-8.0.24-1.el7.x86_64                   3&#x2F;9 </span><br><span class="line">  Verifying  : mysql-community-libs-compat-8.0.24-1.el7.x86_64              4&#x2F;9 </span><br><span class="line">  Verifying  : mysql-community-libs-8.0.24-1.el7.x86_64                     5&#x2F;9 </span><br><span class="line">  Verifying  : mysql-community-client-plugins-8.0.24-1.el7.x86_64           6&#x2F;9 </span><br><span class="line">  Verifying  : 2:postfix-2.10.1-9.el7.x86_64                                7&#x2F;9 </span><br><span class="line">  Verifying  : 2:postfix-2.10.1-6.el7.x86_64                                8&#x2F;9 </span><br><span class="line">  Verifying  : 1:mariadb-libs-5.5.52-1.el7.x86_64                           9&#x2F;9 </span><br><span class="line"></span><br><span class="line">Installed:</span><br><span class="line">  mysql-community-libs.x86_64 0:8.0.24-1.el7                                    </span><br><span class="line">  mysql-community-libs-compat.x86_64 0:8.0.24-1.el7                             </span><br><span class="line">  mysql-community-server.x86_64 0:8.0.24-1.el7                                  </span><br><span class="line"></span><br><span class="line">Dependency Installed:</span><br><span class="line">  mysql-community-client.x86_64 0:8.0.24-1.el7                                  </span><br><span class="line">  mysql-community-client-plugins.x86_64 0:8.0.24-1.el7                          </span><br><span class="line">  mysql-community-common.x86_64 0:8.0.24-1.el7                                  </span><br><span class="line"></span><br><span class="line">Dependency Updated:</span><br><span class="line">  postfix.x86_64 2:2.10.1-9.el7                                                 </span><br><span class="line"></span><br><span class="line">Replaced:</span><br><span class="line">  mariadb-libs.x86_64 1:5.5.52-1.el7                                            </span><br><span class="line"></span><br><span class="line">Complete!</span><br></pre></td></tr></table></figure>
<p>MySQL服务操作</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"># 启动服务</span><br><span class="line">systemctl start mysqld</span><br><span class="line"></span><br><span class="line"># 查看服务</span><br><span class="line">systemctl status mysqld</span><br></pre></td></tr></table></figure>
<p>修改 MySQL 中 root 本地登录密码</p>
<p>先在日志中查找 生成的密码</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">grep &#39;temporary password&#39; &#x2F;var&#x2F;log&#x2F;mysqld.log</span><br><span class="line"></span><br><span class="line"># 查看结果</span><br><span class="line">2021-04-21T13:12:52.469425Z 6 [Note] [MY-010454] [Server]</span><br><span class="line">A temporary password is generated for root@localhost: CwPfkidp2m+s  #最后这一串为初始密码</span><br></pre></td></tr></table></figure>


<p>使用密码root登录</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mysql -u root -p</span><br></pre></td></tr></table></figure>
<p>不过进行其他操作的时候，会发现 提示你用alert 语句去修改密码，这个密码只是临时密码。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">mysql&gt; use mysql</span><br><span class="line">ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.</span><br></pre></td></tr></table></figure>


<p>修改root用户密码</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ALTER USER &#39;root&#39;@&#39;localhost&#39; IDENTIFIED BY &#39;Guo_1234&#39;; #密码开头必须大写，必须有下划线</span><br></pre></td></tr></table></figure>

<p>退出mysql</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Ctrl+Z</span><br></pre></td></tr></table></figure>


<p>修改密码策略</p>
<p>在/etc/my.cnf文件添加validate_password_policy配置，指定密码策略<br>选择0（LOW），1（MEDIUM），2（STRONG）其中一种，选择2需要提供密码字典文件</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">validate_password_policy&#x3D;0</span><br></pre></td></tr></table></figure>
<p>如果不需要密码策略，添加my.cnf文件中添加如下配置禁用即可：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">validate_password &#x3D; off</span><br></pre></td></tr></table></figure>


<p>重新启动mysql服务使配置生效：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">systemctl restart mysqld</span><br></pre></td></tr></table></figure>


<p>允许远程登录</p>
<p>MySQL默认只允许root帐户在本地登录，想要远程连接MySQL，必须开启root用户允许远程连接，或者添加一个允许远程连接的帐户。</p>
<p>首先查看mysql的 user表</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br></pre></td><td class="code"><pre><span class="line">select * from user \G</span><br><span class="line"></span><br><span class="line">*************************** 4. row ***************************</span><br><span class="line">                    Host: localhost</span><br><span class="line">                    User: root</span><br><span class="line">             Select_priv: Y</span><br><span class="line">             Insert_priv: Y</span><br><span class="line">             Update_priv: Y</span><br><span class="line">             Delete_priv: Y</span><br><span class="line">             Create_priv: Y</span><br><span class="line">               Drop_priv: Y</span><br><span class="line">             Reload_priv: Y</span><br><span class="line">           Shutdown_priv: Y</span><br><span class="line">            Process_priv: Y</span><br><span class="line">               File_priv: Y</span><br><span class="line">              Grant_priv: Y</span><br><span class="line">         References_priv: Y</span><br><span class="line">              Index_priv: Y</span><br><span class="line">              Alter_priv: Y</span><br><span class="line">            Show_db_priv: Y</span><br><span class="line">              Super_priv: Y</span><br><span class="line">   Create_tmp_table_priv: Y</span><br><span class="line">        Lock_tables_priv: Y</span><br><span class="line">            Execute_priv: Y</span><br><span class="line">         Repl_slave_priv: Y</span><br><span class="line">        Repl_client_priv: Y</span><br><span class="line">        Create_view_priv: Y</span><br><span class="line">          Show_view_priv: Y</span><br><span class="line">     Create_routine_priv: Y</span><br><span class="line">      Alter_routine_priv: Y</span><br><span class="line">        Create_user_priv: Y</span><br><span class="line">              Event_priv: Y</span><br><span class="line">            Trigger_priv: Y</span><br><span class="line">  Create_tablespace_priv: Y</span><br><span class="line">                ssl_type:</span><br><span class="line">              ssl_cipher: 0x</span><br><span class="line">             x509_issuer: 0x</span><br><span class="line">            x509_subject: 0x</span><br><span class="line">           max_questions: 0</span><br><span class="line">             max_updates: 0</span><br><span class="line">         max_connections: 0</span><br><span class="line">    max_user_connections: 0</span><br><span class="line">                  plugin: caching_sha2_password</span><br><span class="line">   authentication_string: $A$005$QVf&#96;</span><br><span class="line">hi@? _:w.FDDatpHPPpgl.7j830gDg9X.HbKF05PzcdmXptHuD</span><br><span class="line">        password_expired: N</span><br><span class="line">   password_last_changed: 2020-08-03 20:01:07</span><br><span class="line">       password_lifetime: NULL</span><br><span class="line">          account_locked: N</span><br><span class="line">        Create_role_priv: Y</span><br><span class="line">          Drop_role_priv: Y</span><br><span class="line">  Password_reuse_history: NULL</span><br><span class="line">     Password_reuse_time: NULL</span><br><span class="line">Password_require_current: NULL</span><br><span class="line">         User_attributes: NULL</span><br><span class="line">4 rows in set (0.01 sec)</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<p>可以看到 root用户默认只能访问localhost   也就是只能本地登录，不能远程登录。</p>
<p>查询mysql具体版本</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">SELECT @@VERSION</span><br><span class="line"></span><br><span class="line">mysql&gt; select @@VERSION;</span><br><span class="line">+-----------+</span><br><span class="line">| @@VERSION |</span><br><span class="line">+-----------+</span><br><span class="line">| 8.0.21    |</span><br><span class="line">+-----------+</span><br><span class="line"></span><br></pre></td></tr></table></figure>


<p>创建可以远程访问的root用户</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">create user &#39;root&#39;@&#39;%&#39; identified by  &#39;Guo_1234&#39;;</span><br></pre></td></tr></table></figure>
<p>给远程root用户赋予权限</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">grant all privileges on *.* to &#39;root&#39;@&#39;%&#39; with grant option;</span><br></pre></td></tr></table></figure>
<p>操作后要执行刷新，远程用户才能有效</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">flush privileges;</span><br></pre></td></tr></table></figure>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://shangguan-lingfeng.gitee.io/blog1/2021/04/21/CentOS%E4%B8%8A%E5%AE%89%E8%A3%85mysql/" data-id="cknublgb80001v8uh3r9y9fdc" data-title="CentOS上安装mysql" class="article-share-link">Teilen</a>
      
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/blog1/tags/CentOS/" rel="tag">CentOS</a></li></ul>

    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/blog1/2021/04/22/flask%E5%AE%9E%E7%8E%B0%E5%9B%BE%E7%89%87%E9%AA%8C%E8%AF%81%E7%A0%81(%E6%9C%AA%E5%AE%8C%E6%88%90)/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Neuer</strong>
      <div class="article-nav-title">
        
          flak实现图片验证码(未完成)
        
      </div>
    </a>
  
  
    <a href="/blog1/2021/04/20/CentOS%E4%B8%AD%E5%AE%89%E8%A3%85nginx/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Älter</strong>
      <div class="article-nav-title">CentOS中安装nginx</div>
    </a>
  
</nav>

  
</article>


</section>
        
          <aside id="sidebar">
  
    

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tags</h3>
    <div class="widget">
      <ul class="tag-list" itemprop="keywords"><li class="tag-list-item"><a class="tag-list-link" href="/blog1/tags/CentOS/" rel="tag">CentOS</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog1/tags/Flask/" rel="tag">Flask</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog1/tags/django/" rel="tag">django</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog1/tags/docker/" rel="tag">docker</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog1/tags/gitee/" rel="tag">gitee</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog1/tags/linux/" rel="tag">linux</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog1/tags/mysql/" rel="tag">mysql</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog1/tags/python/" rel="tag">python</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog1/tags/python%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86/" rel="tag">python基础知识</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog1/tags/redis/" rel="tag">redis</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog1/tags/vue/" rel="tag">vue</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog1/tags/webshell/" rel="tag">webshell</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog1/tags/%E4%BA%91%E4%B8%BB%E6%9C%BA%E5%AE%9E%E7%8E%B0%E8%A7%86%E9%A2%91%E7%9B%B4%E6%92%AD/" rel="tag">云主机实现视频直播</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog1/tags/%E5%85%B3%E4%BA%8E%E7%AC%AC%E4%B8%89%E6%96%B9/" rel="tag">关于第三方</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tag Cloud</h3>
    <div class="widget tagcloud">
      <a href="/blog1/tags/CentOS/" style="font-size: 17.5px;">CentOS</a> <a href="/blog1/tags/Flask/" style="font-size: 10px;">Flask</a> <a href="/blog1/tags/django/" style="font-size: 12.5px;">django</a> <a href="/blog1/tags/docker/" style="font-size: 12.5px;">docker</a> <a href="/blog1/tags/gitee/" style="font-size: 10px;">gitee</a> <a href="/blog1/tags/linux/" style="font-size: 10px;">linux</a> <a href="/blog1/tags/mysql/" style="font-size: 12.5px;">mysql</a> <a href="/blog1/tags/python/" style="font-size: 15px;">python</a> <a href="/blog1/tags/python%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86/" style="font-size: 17.5px;">python基础知识</a> <a href="/blog1/tags/redis/" style="font-size: 12.5px;">redis</a> <a href="/blog1/tags/vue/" style="font-size: 20px;">vue</a> <a href="/blog1/tags/webshell/" style="font-size: 10px;">webshell</a> <a href="/blog1/tags/%E4%BA%91%E4%B8%BB%E6%9C%BA%E5%AE%9E%E7%8E%B0%E8%A7%86%E9%A2%91%E7%9B%B4%E6%92%AD/" style="font-size: 10px;">云主机实现视频直播</a> <a href="/blog1/tags/%E5%85%B3%E4%BA%8E%E7%AC%AC%E4%B8%89%E6%96%B9/" style="font-size: 12.5px;">关于第三方</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archiv</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/blog1/archives/2021/05/">五月 2021</a></li><li class="archive-list-item"><a class="archive-list-link" href="/blog1/archives/2021/04/">四月 2021</a></li><li class="archive-list-item"><a class="archive-list-link" href="/blog1/archives/2021/03/">三月 2021</a></li><li class="archive-list-item"><a class="archive-list-link" href="/blog1/archives/2021/02/">二月 2021</a></li><li class="archive-list-item"><a class="archive-list-link" href="/blog1/archives/2021/01/">一月 2021</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">letzter Beitrag</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/blog1/2021/05/14/docker+CentOS+mysql%E5%AE%9E%E7%8E%B0%E4%B8%BB%E4%BB%8E%E5%90%8C%E6%AD%A5/">docker+CentOS+mysql实现主从同步</a>
          </li>
        
          <li>
            <a href="/blog1/2021/05/13/mysql%E5%AE%9E%E7%8E%B0%E8%AF%BB%E5%86%99%E5%88%86%E7%A6%BB(%E5%9C%A8%E4%B8%BB%E4%BB%8E%E5%90%8C%E6%AD%A5%E5%9F%BA%E7%A1%80%E4%B8%8A)/">mysql实现读写分离</a>
          </li>
        
          <li>
            <a href="/blog1/2021/05/12/%E5%9C%A8%E9%A1%B9%E7%9B%AE%E4%B8%AD%E8%87%AA%E5%8A%A8%E7%94%9F%E6%88%90%E6%8E%A5%E5%8F%A3%E6%96%87%E6%A1%A3/">在项目中自动生成接口文档</a>
          </li>
        
          <li>
            <a href="/blog1/2021/05/12/mysql%E5%AE%9E%E7%8E%B0%E4%B8%BB%E4%BB%8E%E5%90%8C%E6%AD%A5/">mysql实现主从同步</a>
          </li>
        
          <li>
            <a href="/blog1/2021/05/09/CentOS%E9%83%A8%E7%BD%B2flask%E9%A1%B9%E7%9B%AE/">nginx部署flask项目</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      
      &copy; 2021 Jerry<br>
      Powered by <a href="https://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>

    </div>
    <nav id="mobile-nav">
  
    <a href="/blog1/" class="mobile-nav-link">Home</a>
  
    <a href="/blog1/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    


<script src="/blog1/js/jquery-3.4.1.min.js"></script>



  
<script src="/blog1/fancybox/jquery.fancybox.min.js"></script>




<script src="/blog1/js/script.js"></script>





  </div>
</body>
</html>